<%@page contentType="text/html; UTF-8" pageEncoding="UTF-8" isELIgnored="false" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>注册界面</title>
</head>
<script src="https://libs.baidu.com/jquery/1.8.3/jquery.js"></script>
<script type="text/javascript">

    function submitForm() {

        var repass = document.getElementById("repass").value;
        var password = document.getElementById("password").value;
        if (repass != password) {
            alert("两次密码不同，请重新输入");
        }

        var inputCode=$("#authCode").attr("value");
        var list={"inputCode":inputCode};
        $.ajax({
            //请求方式
            type : "POST",
            //请求的媒体类型
            contentType: "application/x-www-form-urlencoded",
            //请求地址
            url : "yanzheng/checkCode",
            //数据，json字符串
            data :list,
            dataType:"json",
            //请求成功
            success : function(result) {
                if(result=="1"){
                    alert("验证通过");
                }else{
                    alert("验证失败，重新刷新验证码");
                    flushAuthCode();
                }
            },
            //请求失败，包含具体的错误信息
            error : function(e){
                alert(e.responseText);
            }
        });
    }
    function flushAuthCode() {
        //重新刷新验证码
        $("#codeImage").attr("src","yanzheng/yanzhengCode?abc="+Math.random());
    }
</script>
<body align="center">
    <h2>用户注册</h2>
    <form action="${pageContext.request.contextPath}/user/regist" method="post" enctype="multipart/form-data">
        <table align="center">
            <tr align="right">
                <td>请输入用户名:</td>
                <td><input type="text" name="username" autofocus="autofocus"></td>
            </tr>

            <tr align="right">
                <td>请输入密码:</td>
                <td><input type="password" name="password" id="password"></td>
            </tr>

            <tr align="right">
                <td>请输入确认密码:</td>
                <td><input type="password" name="repass" id="repass" ></td>
            </tr>

            <tr align="right">
                <td>请输入验证码:</td>
                <td><input type="text" id="authCode" name="authCode"></td>
                <td> <img type="image" src="yanzheng/yanzhengCode" id="codeImage" name="codeImage" style="cursor:pointer;"onclick="flushAuthCode()"/></td>
            </tr>
        </table>
        <br>

        <input type="submit" name="register" value="注册"  onclick="submitForm()">&nbsp&nbsp&nbsp
        <input type="reset" name="refill" value="重填" >
    </form>

</body>
</html>
